package com.clpms.controller;

import com.clpms.bean.req.AddWorkReq;
import com.clpms.bean.req.DeleteWorkReq;
import com.clpms.bean.req.QueryWorkReq;
import com.clpms.bean.req.UpdateWorkReq;
import com.clpms.bean.resp.QueryWorkResp;
import com.clpms.service.WorkService;
import com.clpms.utils.ResultDto;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author caixinyong
 * @date 2023/5/11 8:49 PM
 */

@RestController
@RequestMapping("/work/v1")
@Slf4j
public class WorkController {
	@Resource
	private WorkService workService;

	@PostMapping("/queryWork")
	ResultDto<PageInfo<QueryWorkResp>> queryWork(@RequestBody @Valid QueryWorkReq req) {
		PageInfo<QueryWorkResp> pageInfo = workService.queryWork(req);
		return ResultDto.Success(pageInfo);
	}

	@PostMapping("/addWork")
	ResultDto<Boolean> addWork(@RequestBody @Valid AddWorkReq req) {
		Boolean result = workService.addWork(req);
		return ResultDto.Success(result);
	}

	@PostMapping("/deleteWork")
	ResultDto<Boolean> deleteWork(@RequestBody @Valid DeleteWorkReq req) {
		Boolean result = workService.deleteWork(req);
		return ResultDto.Success(result);
	}


	@PostMapping("/updateWork")
	ResultDto<Boolean> updateWork(@RequestBody @Valid UpdateWorkReq req) {
		Boolean result = workService.updateWork(req);
		return ResultDto.Success(result);
	}
}
